import dotenv from 'dotenv';
import { run } from 'node:test';

// 根据 NODE_ENV 自动加载不同的环境变量文件
const envFile = process.env.NODE_ENV === 'production'
  ? '.env.production'
  : process.env.NODE_ENV === 'test'
    ? '.env.test'
    : '.env';

dotenv.config({ path: envFile });

const config = {
  runningMode: process.env.RUNNING_MODE || 'dev', // dev or prod  
  isDev: process.env.RUNNING_MODE === 'dev',
  isTest: process.env.RUNNING_MODE === 'test',
  isProd: process.env.RUNNING_MODE === 'prod',
  nodeEnv: process.env.NODE_ENV || 'development',
  server: {
    port: process.env.PORT || 3002
  },
  db: {
    user: process.env.DB_USER || 'postgres',
    host: process.env.DB_HOST || 'localhost',
    database: process.env.DB_NAME || 'wordcurve',
    password: process.env.DB_PASSWORD || 'password',
    port: Number(process.env.DB_PORT) || 5432
  },
  jwt: {
    secret: process.env.JWT_SECRET || 'your_jwt_secret',
    expiresIn: '7d'
  },
  trtc: {
    sdkAppId: process.env.TRTC_SDK_APPID ? Number(process.env.TRTC_SDK_APPID) : 0,
    secretKey: process.env.TRTC_SECRET_KEY || '',
    defaultExpire: 604800 // 7天过期时间
  },
  lke: {
    secretId: process.env.TENCENT_LKE_SDK_APPID || '',
    secretKey: process.env.TENCENT_LKE_SECRET_KEY || '',
    region: process.env.TENCENT_REGION || 'ap-guangzhou',
  },
  tts:{
    secretId: process.env.TENCENT_TTS_SDK_APPID || '',
    secretKey: process.env.TENCENT_TTS_SECRET_KEY || '',
  },
  aliyunsms: {
    accessKeyId: process.env.ALIYUN_SMS_ACCESS_KEY_ID || '',
    accessKeySecret: process.env.ALIYUN_SMS_ACCESS_KEY_SECRET || '',
    signName: process.env.ALIYUN_SMS_SIGN_NAME || '',
    templateCode: process.env.ALIYUN_SMS_TEMPLATE_CODE || ''
  },
  tencentsms:{
    secretId: process.env.TENCENT_SMS_SECRET_ID || '',
    secretKey: process.env.TENCENT_SMS_SECRET_KEY || '',
    signName: process.env.TENCENT_SMS_SIGN_NAME || '',
    templateId: process.env.TENCENT_SMS_TEMPLATE_ID || ''
  },
  cdnBaseUrl: process.env.CDN_BASE_URL || '',
  beauty: {
    token: process.env.BEAUTY_TOKEN || '',
    appId: process.env.BEAUTY_APPID || '',
    licenseKey: process.env.BEAUTY_LICENSE_KEY || ''
  },
  wechat: {
    appId: process.env.WxAppID || '',
    appSecret: process.env.WxAppSecret || '',
  }
};

export default config; 